<?php

namespace App\Service;

use App\Constants\ErrorCode;
use App\Model\Channel;
use App\Model\LinkChannel;
use App\Model\LinkFile;
use App\Model\LinkIndustry;
use App\Model\Product;
use App\Model\ProductSpecKey;
use App\Model\ProductSpecValue;
use Hyperf\DbConnection\Db;
use Hyperf\Snowflake\IdGeneratorInterface;
use Hyperf\Utils\ApplicationContext;
use Psr\Container\ContainerInterface;
use Hyperf\Di\Annotation\Inject;
use Psr\Http\Message\ResponseInterface;

class ProductSpecKeyService extends BaseService
{
    //   新增单条  包括关联关系
    /**
     * @param array $spec_key
     * @param int $product_id
     * @return array
     */
    //    关联数据更新
    public function  key_update_insert(array  $spec_key,$product_id)
    {
        $arr = [];
        foreach ($spec_key as $key=>$value){
                $this->update_insert([
                    'spec_name'=>$value,
                    'product_id'=>$product_id,
                ],[
                    'spec_name'=>$value,
                    'product_id'=>$product_id,
                ]);
        }
        return true;
    }
    //    关联数据更新
    public function  key_update(array  $spec_key,$product_id)
    {
        $arr = [];
        $SpecKeyModel = New ProductSpecKey();
        foreach ($spec_key as $key=>$value){
            $SpecKeyModel->where('id',$value['id'])->update([
                'id'=>$value['id'],
                'spec_name'=>$value['spec_name'],
                'product_id'=>$product_id,
            ]);
        }
        return true;
    }
}